﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Refraction
{
    public class BasicTechnique : Actor
    {    
        private Texture2D _displacementMap;
        public bool IsDraw = false;
        public RenderTarget2D Scene { get; set; }

        public BasicTechnique(Game game, Vector3 position) : base(game, position)
        {
            
        }

        protected override void LoadContent()
        {
            _effect = Game.Content.Load<Effect>("Shaders/BasicRefractionTechnique");
            _model = Game.Content.Load<Model>("Models/ball");
            _displacementMap = Game.Content.Load<Texture2D>("Textures/bumpMap");

            _effect.Parameters["DisplacementMap"].SetValue(_displacementMap);

            Scene = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height,
                    false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {
            _effect.Parameters["RefractionScale"].SetValue(RefractionScale);
            _effect.Parameters["View"].SetValue(Camera.view);
            _effect.Parameters["Projection"].SetValue(Camera.projection);

            base.Update(gameTime);
        }


        public override void Draw(GameTime gameTime)
        {
            if (IsDraw)
            {
                Matrix world = Matrix.CreateScale(5f)*Matrix.CreateTranslation(Position);
                _effect.Parameters["SceneTexture"].SetValue(Scene);

                DrawModel(world);
            }

            base.Draw(gameTime);
        }
    }
}
